package com.more.offer.threadtest.juctest;

import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.LongAdder;
import java.util.concurrent.locks.LockSupport;

/**
 * @author pinoc
 * @date 2021/6/24
 * @description
 */
public class AtomicLongTest {

	private static AtomicLong atomicLong = new AtomicLong();
	
	private static Integer[] arrayOne = new Integer[]{1,2,3,0,5,6,0,56,0};
	private static Integer[] arrayzTwo = new Integer[]{1,2,3,0,5,6,0,56,0};
	public static void main(String[] args) throws InterruptedException {

		Thread thread = new Thread(() -> {
			int size = arrayOne.length;
			for (int i = 0; i < size; ++i) {
				if (arrayOne[i].intValue() == 0) {
					atomicLong.incrementAndGet();
				}
			}
		});

		Thread thread2 = new Thread(() -> {
			int size = arrayzTwo.length;
			for (int i = 0; i < size; ++i) {
				if (arrayzTwo[i].intValue() == 0) {
					atomicLong.getAndIncrement();
					atomicLong.incrementAndGet();
				}
			}
		});

		thread.start();
		thread2.start();
		thread.join();
		thread.join();

		System.out.println("count 0: " + atomicLong.get());
	}
}
